﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Windows.Forms;
using System.Threading;
using System.ComponentModel;
using System.Windows;
using System.Reflection;
using System.IO;

namespace RadarA
{
    public partial class Form1 : Form
    {
        RadaA1 radar;
        int speed = 200;
        MucTieu mb;
        List<ToaDo> qd;
        System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer t2 = new System.Windows.Forms.Timer();
        System.Windows.Forms.Timer timerGiaotiepPhanCung = new System.Windows.Forms.Timer();
        public static ListView lvTarget = new ListView();
        public static float culy;
        public static float phuongvi;
        string pathicon = string.Empty;
        private bool Updatevitri;
        private List<MucTieu> listTarget=new List<MucTieu>();
        private string controldangchon;
        private string strNumericUpDown;
        private bool luachon;
        int solanluachon = 0;
        public static bool muctieuBam;
        private bool bamgiu;
        private int aa;
        public static Hashtable clientsList = new Hashtable();
        
        public Form1()
        {
            InitializeComponent();
            //t.Interval = 500;
            //t.Tick += new EventHandler(t_Tick);
            //t.Enabled = true;

            //t2.Interval = 1200;
            //t2.Tick += new EventHandler(t2_Tick);
            //t2.Enabled = true;

            //timerGiaotiepPhanCung.Interval = 500;
            //timerGiaotiepPhanCung.Tick += new EventHandler(timerGiaotiepPhanCung_Tick);
            //timerGiaotiepPhanCung.Enabled = true;
            clsCommons.lstTarget = new List<MucTieu>();
        }

        //void timerGiaotiepPhanCung_Tick(object sender, EventArgs e)
        //{
        //    if (string.IsNullOrEmpty(cl.getInputData()))
        //    {
        //        return;
        //    }
        //    NumberButtnSetVanlue(controldangchon, cl.getInputData());
        //}
        
        //3 giây tick 1 lần
        //void t2_Tick(object sender, EventArgs e)
        //{
        //    textBoxDkm.Text = clsCommons.Dkm;
        //    textBoxVvt.Text = clsCommons.Vvt;
        //    textBoxHkm.Text = clsCommons.Hkm;
        //    //string tatmay;
        //    //tatmay=cl.GetData();
        //    //if (tatmay=="TM")
        //    //{
        //    //    Application.Exit();
        //    //}
        //}


        //void t_Tick(object sender, EventArgs e)
        //{
        //    double max_angle = radar.maxAngle * 0.0174532925d;

        //    if (listTarget.Count==0)
        //    {
                
        //    }
        //    else
        //    {
        //        //lvTarget.Items.Clear();
        //        //cbTarget.Items.Clear();
        //        // select which of the three items to update
        //        foreach (MucTieu item in listTarget)
        //        {
        //            //khoang cach di duoc cua muc tieu trong 1 s
        //            //double s = item._current.velocity * 1000 / (3600000 * 3);
        //            double s = item._current.velocity * 1000 / (3600 * 30);

        //            //toa do tuong doi giua diem di va diem den
        //            double x = item._to.X - item._current.X;
        //            double y = item._to.Y - item._current.Y;
        //            double chenhlech_kc = Math.Sqrt(x * x + y * y);
        //            double gocngang = Math.Acos(x / chenhlech_kc);
        //            //doi sang do.
        //            gocngang = gocngang / 0.0174532925d;

        //            if (y < 0)
        //            {
        //                gocngang = 360d - gocngang;
        //            }
        //            //doi sang radian de tinh sin va cos
        //            gocngang *= 0.0174532925d;
        //            double z = item._to.Z - item._current.Z;
        //            double gocdung = Math.Asin(z / Math.Sqrt(z * z + chenhlech_kc * chenhlech_kc));
        //            //toa do muc tieu sau 1s
        //            double z1 = item._current.Z + (s * Math.Sin(gocdung));
        //            double chenhlech_kc1 = (float)(s * Math.Abs(Math.Cos(gocdung)));

        //            double x1 = item._current.X + chenhlech_kc1 * Math.Cos(gocngang);
        //            double y1 = item._current.Y + chenhlech_kc1 * Math.Sin(gocngang);
        //            int dKm = item._current._Dkm;
        //            ToaDo current = new ToaDo(item._current.stt, x1, y1,dKm, z1, item._current.velocity, "abc");
        //            //gan diem nay thanh diem bat dau
        //            item._current = current;
        //            //_radar.AddItem(item);

        //            //_radar.ImageUpdate += new ImageUpdateHandler(_radar_ImageUpdate);
        //            if (radar._az + 20 > RadaA1.getAzimuth(current) && radar._az - 20 < RadaA1.getAzimuth(current) && RadaA1.getRange(current) <= pictureBox1.Width / 2)// && (RadaA1.getRange(item._current) * Math.Sin(max_angle)) > item._current.Z)
        //            {


        //                bool Flag = true;
        //                for (int j = 0; j < lvTarget.Items.Count; j++)
        //                {

        //                    if (lvTarget.Items[j].Text.Trim() == item.ID.ToString().Trim())
        //                    {
        //                        ListViewItem lvItem = lvTarget.Items[j];
        //                        lvItem.Text = item.ID.ToString();
        //                        lvItem.SubItems[1].Text = (item._category);
        //                        lvItem.SubItems[2].Text = (RadaA1.getAzimuth(item._current).ToString());

        //                        int rg = (int)RadaA1.getRange(item._current);

        //                        lvItem.SubItems[3].Text = (rg.ToString());
        //                        lvItem.SubItems[4].Text = (item._current.Z.ToString());
        //                        lvItem.SubItems[5].Text = (item._current.velocity.ToString());
        //                        Flag = false;
        //                        if (muctieuBam)
        //                        {
        //                            textBox3.Text = Convert.ToInt16(getAzimuth(Convert.ToInt16(item._to.X), Convert.ToInt16(item._to.Y), pictureBox1.Width)).ToString();
        //                            textBox1.Text = item._current._Dkm.ToString();
        //                            textBox7.Text = item._current.Z.ToString();
        //                        }
        //                        int abc = checkmousemove(Convert.ToInt16(item._current.X), Convert.ToInt16(item._current.Y), pictureBox1.Width);
        //                        if (abc==240)
        //                        {
        //                            lvTarget.Items.RemoveByKey(item.ID.ToString());
        //                        }
        //                        else
        //                        {
        //                            radar.AddItem(item);
        //                        }
        //                        //radar.ImageUpdate += new ImageUpdateHandler(_radar_ImageUpdate);
        //                    }
        //                }
        //                if (Flag)
        //                {
        //                    ListViewItem lvItem = new ListViewItem();
        //                    lvItem.Text = item.ID.ToString();
        //                    lvItem.SubItems.Add(item._category);
        //                    lvItem.SubItems.Add(RadaA1.getAzimuth(item._current).ToString());

        //                    int rg = (int)RadaA1.getRange(item._current);

        //                    lvItem.SubItems.Add(rg.ToString());
        //                    lvItem.SubItems.Add(item._current.Z.ToString());
        //                    lvItem.SubItems.Add(item._current.velocity.ToString());
        //                    lvItem.BackColor = item._color;
        //                    lvTarget.Items.Add(lvItem);
        //                }
        //            }
        //        }
        //    }
        //}

        private void Form1_Load(object sender, EventArgs e)
        {
            panel18.Controls.Add(new UserControl3vongtron());
            //cl.SetData(0);
            checkFulScree();
            clsCommons.bonhao = false;
            clsCommons.showBonhao = false;
            button11.Font = new Font("Georgia", 12);
        }

        private void checkFulScree()
        {
            if (this.WindowState == FormWindowState.Maximized)
            {
                button52.Width = 100;
                button52.Height = 150;
            }
        }

        private void _radar_ImageUpdate(object sender, ImageUpdateEventArgs e)
        {
            //pictureBox1.Image = e.Image; 
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void pictureBox1_MouseMove_1(object sender, MouseEventArgs e)
        {
           // toado.Text = "Cự ly: " + e.Location.X.ToString() + " Phương vị " + e.Location.Y.ToString();
           //int abc = checkmousemove(e.Location.X, e.Location.Y, pictureBox1.Width);


           // if (abc <= 240)
           // {
           //     int ab = getAzimuth(e.Location.X, e.Location.Y, pictureBox1.Width);
           //     toado.Text = "Cự ly: " + e.Location.X.ToString() + " Phương vị " + e.Location.Y.ToString();
           //     lblPhuongVi.Text = "hướng: " + ab.ToString();
           //     lblCuLy.Text = "Db:"+Convert.ToInt16(getRange(e.Location.X, e.Location.Y, pictureBox1.Width)).ToString();
           // }
        }

        private int getAzimuth(int _x, int _y, int size)
        {
            double r, x, y;
            r = size * 0.5d;//ban kinh duong tron
            //xac dinh toa do so voi tam
            x = _x - r;
            y = _y - r;
            double canh_huyen = Math.Sqrt(x * x + y * y);
            //tinh goc so voi truc x
            double angle = Math.Acos(x / canh_huyen);
            //doi sang do.
            angle = angle / 0.0174532925d;

            if (y < 0)
            {
                angle = 360d - angle;
            }
            //chuyen sang goc so voi truc. y - Phuong BAC'

            double azimuth = angle - 270d;
            if (azimuth < 0) azimuth = azimuth + 360d;
            return (int)azimuth;
        }
        public PointF huong(int azimuth, int widthPictrueBox)
        {
            int _size = widthPictrueBox;
            //chuyen goc phuong vi sang goc theo truc X
            double angle = (270d + (double)azimuth);

            // chuyen sang radian
            angle *= 0.0174532925d;

            double r, x, y;

            // tinh x va y theo size cua man hinh scan radar co san
            r = _size * 0.5;

            //_size = pictureBox1.Width;

            x = (((double)_size * 0.5d) + (r * Math.Cos(angle)));
            y = (((double)_size * 0.5d) + (r * Math.Sin(angle)));

            return new PointF((float)x, (float)y);
        }

        private int checkmousemove(int _x, int _y, int size)
        {
            double r, x, y;
            r = size * 0.5d;//ban kinh duong tron
            //xac dinh toa do so voi tam
            x = _x - r;
            y = _y - r;
            double canh_huyen = Math.Sqrt(x * x + y * y);
            return Convert.ToInt16(canh_huyen);
        }

        private void butMoQuayAnten08_Click(object sender, EventArgs e)
        {
            RadaA1.TatmoAnten = true;
            //rdMoAnTen03.Checked = true;
            butMoQuayAnten08.BackColor = Color.Blue;
            butTatQuayAnten09.BackColor = Color.White;
        }

        private void butTatQuayAnten09_Click(object sender, EventArgs e)
        {
            RadaA1.TatmoAnten = false;
            butMoQuayAnten08.BackColor = Color.White;
            butTatQuayAnten09.BackColor = Color.Blue;
        }

        private void button17_Click(object sender, EventArgs e)
        {
            radar.DrawScanInterval = 40;
        }

        private void button22_Click(object sender, EventArgs e)
        {
            //5 giây
            radar.DrawScanInterval = speed / 20;
        }

        private void button23_Click(object sender, EventArgs e)
        {
            //10 giây
            radar.DrawScanInterval = speed / 20;
        }

        private void button28_Click(object sender, EventArgs e)
        {
            //10 giay
            radar.DrawScanInterval = speed / 20;
        }

        private void button27_Click(object sender, EventArgs e)
        {
            //20 giay
            radar.DrawScanInterval = speed / 10;
        }
        //hàm tính vị trí so với tâm
        public static double getRange(int _x, int _y, int size)
        {
            double r, x, y;
            r = size * 0.5d;//ban kinh duong tron
            //xac dinh toa do so voi tam
            x = _x - r;
            y = _y - r;
            double canh_huyen = Math.Sqrt(x * x + y * y);
            return Convert.ToInt16(canh_huyen)/8;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //button4.Enabled = false;
            
            //int Dkm = Convert.ToInt16(numericUpDown2.Value);
            //int Bdo = Convert.ToInt16(numericUpDown3.Value);
            //int Hkm = Convert.ToInt16(numericUpDown6.Value);
            //int GocT = Convert.ToInt16(numericUpDown7.Value);
            //int Vvt = Convert.ToInt16(numericUpDown8.Value);

            //PointF huongBdo = huong(Bdo, clsCommons.sizePictureBox);
            //PointF huongGocT = huong(GocT, clsCommons.sizePictureBox);

            ////quan su dich Z=14
            //ToaDo td1 = new ToaDo(1, huongBdo.X, huongBdo.Y, Dkm,14, Hkm, Vvt, "abc");
            //ToaDo td2 = new ToaDo(2, huongGocT.X, huongGocT.Y, Dkm,14, Hkm, Vvt, "abc");

            //qd = new List<ToaDo>();
            //qd.Add(td1);
            //qd.Add(td2);
            ////MucTieu mb = new MucTieu("Quân sự (địch)", 5, qd, Color.Red);

            //button4.Enabled = true;
            if (!numericUpDown2.Enabled)
            {
                numericUpDown2.Enabled = true;
                numericUpDown3.Enabled = true;
                numericUpDown6.Enabled = true;
                numericUpDown7.Enabled = true;
                numericUpDown8.Enabled = true;
            }
            else
            {
                numericUpDown2.Enabled = false;
                numericUpDown3.Enabled = false;
                numericUpDown6.Enabled = false;
                numericUpDown7.Enabled = false;
                numericUpDown8.Enabled = false;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            button4.Enabled = false;

            int Dkm = Convert.ToInt16(numericUpDown2.Value);
            int Bdo = Convert.ToInt16(numericUpDown3.Value);
            int Hkm = Convert.ToInt16(numericUpDown6.Value);
            int GocT = Convert.ToInt16(numericUpDown7.Value);
            int Vvt = Convert.ToInt16(numericUpDown8.Value);

            PointF huongBdo = huong(Bdo, clsCommons.sizePictureBox);
            PointF huongGocT = huong(GocT, clsCommons.sizePictureBox);

            //quan su dich Z=14
            ToaDo td1 = new ToaDo(1, huongBdo.X, huongBdo.Y, Dkm, 14, Hkm, Vvt, "abc");
            ToaDo td2 = new ToaDo(2, huongGocT.X, huongGocT.Y, Dkm, 14, Hkm, Vvt, "abc");

            qd = new List<ToaDo>();
            qd.Add(td1);
            qd.Add(td2);
            //MucTieu mb = new MucTieu("Quân sự (địch)", 5, qd, Color.Red);

            button4.Enabled = true;

            mb = new MucTieu("Quân sự (địch)", 1, qd, Color.Red);
            if (clsCommons.lstTarget.Contains(mb))
            {
                clsCommons.lstTarget.Remove(mb);
            }
            clsCommons.lstTarget.Add(mb);
            
            chonmuctieuBam.Items.Clear();
            foreach (var item in clsCommons.lstTarget)
            {
                chonmuctieuBam.Items.Add(item.ID);
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            luachon = false;
            solanluachon = 0;
            //luachonnew.Text = "lua chon: " + solanluachon.ToString();
            //luachonnew.Visible = false;
        }

        #region các điều khiển bàn phím
        private void button3_Click(object sender, EventArgs e)
        {
            strNumericUpDown += "7";
            //NumberButtnSetVanlue(controldangchon, strNumericUpDown);
        }
        //đặt lại giá trị cho numeric đang focus khi bấm các nút số
        private void NumberButtnSetVanlue(string controlFocus, string strNumericUpDown)
        {
            if (controlFocus == "numericUpDown2")
            {
                if (Convert.ToDecimal(strNumericUpDown)>numericUpDown2.Minimum && Convert.ToDecimal(strNumericUpDown)<numericUpDown2.Maximum)
                {
                    numericUpDown2.Value = Convert.ToDecimal(strNumericUpDown);
                }                
            }
            if (controlFocus == "numericUpDown3")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown3.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown3.Maximum)
                {
                    numericUpDown3.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown6")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown6.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown6.Maximum)
                {
                    numericUpDown6.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown7")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown7.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown7.Maximum)
                {
                    numericUpDown7.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown8")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown8.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown8.Maximum)
                {
                    numericUpDown8.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown9")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown9.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown9.Maximum)
                {
                    numericUpDown9.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown10")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown10.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown10.Maximum)
                {
                    numericUpDown10.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }

            if (controlFocus == "numericUpDown11")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown11.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown11.Maximum)
                {
                    numericUpDown11.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown12")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown12.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown12.Maximum)
                {
                    numericUpDown12.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown29")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown29.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown29.Maximum)
                {
                    numericUpDown29.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown22")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown22.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown22.Maximum)
                {
                    numericUpDown22.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown21")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown21.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown21.Maximum)
                {
                    numericUpDown21.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown23")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown23.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown23.Maximum)
                {
                    numericUpDown23.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown24")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown24.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown24.Maximum)
                {
                    numericUpDown24.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown30")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown30.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown30.Maximum)
                {
                    numericUpDown30.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown26")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown26.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown26.Maximum)
                {
                    numericUpDown26.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown25")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown25.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown25.Maximum)
                {
                    numericUpDown25.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown27")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown27.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown27.Maximum)
                {
                    numericUpDown27.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown28")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown28.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown28.Maximum)
                {
                    numericUpDown28.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown31")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown31.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown31.Maximum)
                {
                    numericUpDown31.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown13")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown13.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown13.Maximum)
                {
                    numericUpDown13.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown14")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown14.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown14.Maximum)
                {
                    numericUpDown14.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown15")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown15.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown15.Maximum)
                {
                    numericUpDown15.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown16")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numSomuctieu.Minimum && Convert.ToDecimal(strNumericUpDown) < numSomuctieu.Maximum)
                {
                    numSomuctieu.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown17")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown17.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown17.Maximum)
                {
                    numericUpDown17.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown18")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown18.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown18.Maximum)
                {
                    numericUpDown18.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown19")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown19.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown19.Maximum)
                {
                    numericUpDown19.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown20")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown20.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown20.Maximum)
                {
                    numericUpDown20.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
        }

        private void button50_Click(object sender, EventArgs e)
        {            
            muctieuBam = true;
            chonmuctieuBam.Items.Clear();
            foreach (var item in clsCommons.lstTarget)
            {
                chonmuctieuBam.Items.Add(item.ID);
            }
        }

        private void button49_Click(object sender, EventArgs e)
        {
            ResetValue(controldangchon);
        }
        //đặt lại giá trị cho numeric đang focus khi bấm nút Del
        private void ResetValue(string controlFocus)
        {
            if (controlFocus == "numericUpDown2")
            {
                numericUpDown2.Value = 0;
            }
            if (controlFocus == "numericUpDown3")
            {
                numericUpDown3.Value = 0;
            }
            if (controlFocus == "numericUpDown6")
            {
                numericUpDown6.Value = 0;
            }
            if (controlFocus == "numericUpDown7")
            {
                numericUpDown7.Value = 0;
            }
            if (controlFocus == "numericUpDown8")
            {
                numericUpDown8.Value = 0;
            }
            if (controlFocus == "numericUpDown9")
            {
                numericUpDown9.Value = 0;
            }
            if (controlFocus == "numericUpDown10")
            {
                numericUpDown10.Value = 0;
            }

            if (controlFocus == "numericUpDown11")
            {
                numericUpDown11.Value = 0;
            }
            if (controlFocus == "numericUpDown12")
            {
                numericUpDown12.Value = 0;
            }
            if (controlFocus == "numericUpDown29")
            {
                numericUpDown29.Value = 0;
            }
            if (controlFocus == "numericUpDown22")
            {
                numericUpDown22.Value = 0;
            }
            if (controlFocus == "numericUpDown21")
            {
                numericUpDown21.Value = 0;
            }
            if (controlFocus == "numericUpDown23")
            {
                numericUpDown23.Value = 0;
            }
            if (controlFocus == "numericUpDown24")
            {
                numericUpDown24.Value = 0;
            }
            if (controlFocus == "numericUpDown30")
            {
                numericUpDown30.Value = 0;
            }
            if (controlFocus == "numericUpDown26")
            {
                numericUpDown26.Value = 0;
            }
            if (controlFocus == "numericUpDown25")
            {
                numericUpDown25.Value = 0;
            }
            if (controlFocus == "numericUpDown27")
            {
                numericUpDown27.Value = 0;
            }
            if (controlFocus == "numericUpDown28")
            {
                numericUpDown28.Value = 0;
            }
            if (controlFocus == "numericUpDown31")
            {
                numericUpDown31.Value = 0;
            }
            if (controlFocus == "numericUpDown13")
            {
                numericUpDown13.Value = 0;
            }
            if (controlFocus == "numericUpDown14")
            {
                numericUpDown14.Value = 0;
            }
            if (controlFocus == "numericUpDown15")
            {
                numericUpDown15.Value = 0;
            }
            if (controlFocus == "numericUpDown16")
            {
                numSomuctieu.Value = 0;
            }
            if (controlFocus == "numericUpDown17")
            {
                numericUpDown17.Value = 0;
            }
            if (controlFocus == "numericUpDown18")
            {
                numericUpDown18.Value = 0;
            }
            if (controlFocus == "numericUpDown19")
            {
                numericUpDown19.Value = 0;
            }
            if (controlFocus == "numericUpDown20")
            {
                numericUpDown20.Value = 0;
            }
        }

        private void numericUpDown2_MouseDown(object sender, MouseEventArgs e)
        {
            controldangchon = "numericUpDown2";
        }
        private void numericUpDown3_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown3";
            strNumericUpDown = numericUpDown3.Value.ToString();
        }

        private void numericUpDown6_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown6";
            strNumericUpDown = numericUpDown6.Value.ToString();
        }

        private void numericUpDown7_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown7";
            strNumericUpDown = numericUpDown7.Value.ToString();
        }

        private void numericUpDown8_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown8";
            strNumericUpDown = numericUpDown8.Value.ToString();
        }

        private void numericUpDown9_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown9";
            strNumericUpDown = numericUpDown9.Value.ToString();
        }

        private void numericUpDown10_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown10";
            strNumericUpDown = numericUpDown10.Value.ToString();
        }

        private void numericUpDown11_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown11";
            strNumericUpDown = numericUpDown11.Value.ToString();
        }

        private void numericUpDown12_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown12";
            strNumericUpDown = numericUpDown12.Value.ToString();
        }

        private void numericUpDown29_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown29";
            strNumericUpDown = numericUpDown29.Value.ToString();
        }

        private void numericUpDown22_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown22";
            strNumericUpDown = numericUpDown22.Value.ToString();
        }

        private void numericUpDown21_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown21";
            strNumericUpDown = numericUpDown21.Value.ToString();
        }

        private void numericUpDown23_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown23";
            strNumericUpDown = numericUpDown23.Value.ToString();
        }

        private void numericUpDown24_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown24";
            strNumericUpDown = numericUpDown24.Value.ToString();
        }

        private void numericUpDown30_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown30";
            strNumericUpDown = numericUpDown30.Value.ToString();
        }

        private void numericUpDown26_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown26";
            strNumericUpDown = numericUpDown26.Value.ToString();
        }

        private void numericUpDown25_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown25";
            strNumericUpDown = numericUpDown25.Value.ToString();
        }

        private void numericUpDown27_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown27";
            strNumericUpDown = numericUpDown27.Value.ToString();
        }

        private void numericUpDown28_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown28";
            strNumericUpDown = numericUpDown28.Value.ToString();
        }

        private void numericUpDown31_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown31";
            strNumericUpDown = numericUpDown31.Value.ToString();
        }

        private void numericUpDown13_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown13";
            strNumericUpDown = numericUpDown13.Value.ToString();
        }

        private void numericUpDown14_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown14";
            strNumericUpDown = numericUpDown14.Value.ToString();
        }

        private void numericUpDown15_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown15";
            strNumericUpDown = numericUpDown15.Value.ToString();
        }

        private void numericUpDown16_Leave(object sender, EventArgs e)
        {
            strNumericUpDown = numSomuctieu.Value.ToString();
            controldangchon = "numericUpDown16";
        }

        private void numericUpDown18_Leave(object sender, EventArgs e)
        {
            strNumericUpDown = numericUpDown18.Value.ToString();
            controldangchon = "numericUpDown18";
        }

        private void numericUpDown17_Leave(object sender, EventArgs e)
        {
            strNumericUpDown = numericUpDown17.Value.ToString();
            controldangchon = "numericUpDown17";
        }

        private void numericUpDown19_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown19";
            strNumericUpDown = numericUpDown19.Value.ToString();
        }


        private void numericUpDown20_Leave(object sender, EventArgs e)
        {
            strNumericUpDown = numericUpDown20.Value.ToString();
            controldangchon = "numericUpDown20";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            strNumericUpDown += "8";
            NumberButtnSetVanlue(controldangchon, strNumericUpDown);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            strNumericUpDown += "9";
            NumberButtnSetVanlue(controldangchon, strNumericUpDown);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            strNumericUpDown += "4";
            NumberButtnSetVanlue(controldangchon, strNumericUpDown);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            strNumericUpDown += "5";
            NumberButtnSetVanlue(controldangchon, strNumericUpDown);
        }

        private void button29_Click(object sender, EventArgs e)
        {
            strNumericUpDown += "6";
            NumberButtnSetVanlue(controldangchon, strNumericUpDown);
        }

        private void button31_Click(object sender, EventArgs e)
        {
            strNumericUpDown += "1";
            NumberButtnSetVanlue(controldangchon, strNumericUpDown);
        }

        private void button32_Click(object sender, EventArgs e)
        {
            strNumericUpDown += "2";
            NumberButtnSetVanlue(controldangchon, strNumericUpDown);
        }

        private void button33_Click(object sender, EventArgs e)
        {
            strNumericUpDown += "3";
            NumberButtnSetVanlue(controldangchon, strNumericUpDown);
        }

        private void button48_Click(object sender, EventArgs e)
        {
            strNumericUpDown += "0";
            NumberButtnSetVanlue(controldangchon, strNumericUpDown);
        }

        private void numericUpDown2_Leave(object sender, EventArgs e)
        {
            controldangchon = "numericUpDown2";
            strNumericUpDown = numericUpDown2.Value.ToString();
        }

private void button51_MouseDown(object sender, MouseEventArgs e)
        {
            //luachonnew.Visible = true;
            //luachon = true;
        }

        private void button51_MouseLeave(object sender, EventArgs e)
        {
            //luachon = false;
        }

        private void button35_Click(object sender, EventArgs e)
        {
            if (controldangchon == "numericUpDown2")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown2.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown2.Maximum)
                {
                    numericUpDown2.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controldangchon == "numericUpDown3")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown3.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown3.Maximum)
                {
                    numericUpDown3.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
        }
        private void nhapEnter(string controlFocus, string strNumericUpDown)
        {
            if (controlFocus == "numericUpDown2")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown2.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown2.Maximum)
                {
                    numericUpDown2.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown3")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown3.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown3.Maximum)
                {
                    numericUpDown3.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown6")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown6.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown6.Maximum)
                {
                    numericUpDown6.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown7")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown7.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown7.Maximum)
                {
                    numericUpDown7.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown8")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown8.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown8.Maximum)
                {
                    numericUpDown8.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown9")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown9.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown9.Maximum)
                {
                    numericUpDown9.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown10")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown10.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown10.Maximum)
                {
                    numericUpDown10.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }

            if (controlFocus == "numericUpDown11")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown11.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown11.Maximum)
                {
                    numericUpDown11.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown12")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown12.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown12.Maximum)
                {
                    numericUpDown12.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown29")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown29.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown29.Maximum)
                {
                    numericUpDown29.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown22")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown22.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown22.Maximum)
                {
                    numericUpDown22.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown21")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown21.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown21.Maximum)
                {
                    numericUpDown21.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown23")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown23.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown23.Maximum)
                {
                    numericUpDown23.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown24")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown24.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown24.Maximum)
                {
                    numericUpDown24.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown30")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown30.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown30.Maximum)
                {
                    numericUpDown30.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown26")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown26.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown26.Maximum)
                {
                    numericUpDown26.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown25")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown25.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown25.Maximum)
                {
                    numericUpDown25.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown27")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown27.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown27.Maximum)
                {
                    numericUpDown27.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown28")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown28.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown28.Maximum)
                {
                    numericUpDown28.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown31")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown31.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown31.Maximum)
                {
                    numericUpDown31.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown13")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown13.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown13.Maximum)
                {
                    numericUpDown13.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown14")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown14.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown14.Maximum)
                {
                    numericUpDown14.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown15")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown15.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown15.Maximum)
                {
                    numericUpDown15.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown16")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numSomuctieu.Minimum && Convert.ToDecimal(strNumericUpDown) < numSomuctieu.Maximum)
                {
                    numSomuctieu.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown17")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown17.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown17.Maximum)
                {
                    numericUpDown17.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown18")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown18.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown18.Maximum)
                {
                    numericUpDown18.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown19")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown19.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown19.Maximum)
                {
                    numericUpDown19.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
            if (controlFocus == "numericUpDown20")
            {
                if (Convert.ToDecimal(strNumericUpDown) > numericUpDown20.Minimum && Convert.ToDecimal(strNumericUpDown) < numericUpDown20.Maximum)
                {
                    numericUpDown20.Value = Convert.ToDecimal(strNumericUpDown);
                }
            }
        }
        #endregion   

        private void btnKhoa2_Click(object sender, EventArgs e)
        {
            //button4.Enabled = false;
            //int Dkm = Convert.ToInt16(numericUpDown9.Value);
            //int Bdo = Convert.ToInt16(numericUpDown10.Value);
            //int Hkm = Convert.ToInt16(numericUpDown11.Value);
            //int GocT = Convert.ToInt16(numericUpDown12.Value);
            //int Vvt = Convert.ToInt16(numericUpDown29.Value);

            //PointF huongBdo = huong(Bdo, pictureBox1.Width);
            //PointF huongGocT = huong(GocT, pictureBox1.Width);


            //ToaDo td1 = new ToaDo(1, huongBdo.X, huongBdo.Y,Dkm, Hkm, Vvt, "abc");
            //ToaDo td2 = new ToaDo(2, huongGocT.X, huongGocT.Y,Dkm, Hkm, Vvt, "abc");

            //qd = new List<ToaDo>();
            //qd.Add(td1);
            //qd.Add(td2);
            ////MucTieu mb = new MucTieu("Quân sự (địch)", 5, qd, Color.Red);

            //button4.Enabled = true;
        }

        private void btnmo2_Click(object sender, EventArgs e)
        {
            int Dkm = Convert.ToInt16(numericUpDown9.Value);
            int Bdo = Convert.ToInt16(numericUpDown10.Value);
            int Hkm = Convert.ToInt16(numericUpDown11.Value);
            int GocT = Convert.ToInt16(numericUpDown12.Value);
            int Vvt = Convert.ToInt16(numericUpDown29.Value);

            PointF huongBdo = huong(Bdo, clsCommons.sizePictureBox);
            PointF huongGocT = huong(GocT, clsCommons.sizePictureBox);

            //quan su dich Z=14
            ToaDo td1 = new ToaDo(1, huongBdo.X, huongBdo.Y, Dkm, 14, Hkm, Vvt, "abc");
            ToaDo td2 = new ToaDo(2, huongGocT.X, huongGocT.Y, Dkm, 14, Hkm, Vvt, "abc");

            qd = new List<ToaDo>();
            qd.Add(td1);
            qd.Add(td2);
            //MucTieu mb = new MucTieu("Quân sự (địch)", 5, qd, Color.Red);

            button4.Enabled = true;

            mb = new MucTieu("Quân sự (địch)", 2, qd, Color.Red);
            if (clsCommons.lstTarget.Contains(mb))
            {
                clsCommons.lstTarget.Remove(mb);
            }
            clsCommons.lstTarget.Add(mb);

            chonmuctieuBam.Items.Clear();
            foreach (var item in clsCommons.lstTarget)
            {
                chonmuctieuBam.Items.Add(item.ID);
            }
        }

        private void chonmuctieuBam_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button53_MouseMove(object sender, MouseEventArgs e)
        {

        }

        private void button53_Click(object sender, EventArgs e)
        {
           
        }

        private void panel18_MouseLeave(object sender, EventArgs e)
        {
            
        }

        private void btn3vongtron_Click(object sender, EventArgs e)
        {
            foreach (Control ctrl in panel18.Controls)
            {
                ctrl.Dispose();
            }
            panel18.Controls.Add(new UserControl3vongtron());
        }

        private void btn5vongtron_Click(object sender, EventArgs e)
        {
            foreach (Control ctrl in panel18.Controls)
            {
                ctrl.Dispose();
            }
            panel18.Controls.Add(new UserControl5vongtron());
        }

        private void btn6vongtron_Click(object sender, EventArgs e)
        {
            foreach (Control ctrl in panel18.Controls)
            {
                ctrl.Dispose();
            }
            panel18.Controls.Add(new UserControl6vongtron());
        }

        private void loadVuong_Click(object sender, EventArgs e)
        {
            foreach (Control ctrl in panel18.Controls)
            {
                ctrl.Dispose();
            }
            panel18.Controls.Add(new UserControlhinhvuong());
        }

        

        private void numericUpDown2_MouseDown_2(object sender, MouseEventArgs e)
        {
            controldangchon = "numericUpDown2";
        }

        private void numericUpDown3_MouseDown(object sender, MouseEventArgs e)
        {
            controldangchon = "numericUpDown3";
        }

        private void button44_Click(object sender, EventArgs e)
        {
            panel16.Visible = false;
            panelDSmuctieu.Visible = true;
            Loaddulieu();
        }

        private void Loaddulieu()
        {
            //System.Data.DataTable dt = new System.Data.DataTable();
            //dt = (System.Data.DataTable)dataGridView1.DataSource;
            //System.Data.DataRow dtRow;

            //foreach (var item in clsCommons.lstTarget)
            //{
            //    dtRow = dt.NewRow();
            //    dtRow["STT"] = item._current.stt;
            //    dtRow["Dkm"] = item._current._Dkm;
            //    dtRow["Hkm"] = item._current._Hkm;
            //    dtRow["GocT"] = "";
            //    dtRow["Vvt"] = "";
            //    dt.Rows.Add(dtRow);
            // }
            //dataGridView1.DataSource = dt;
        }

        private void button57_Click(object sender, EventArgs e)
        {
            panelDSmuctieu.Visible = false;
            panel16.Visible = true;
        }

        /*private void label32_Click(object sender, EventArgs e)
        {
            int huongbatdau;

            int Dkm = Convert.ToInt16(numericUpDown13.Value);
            int Hkm = Convert.ToInt16(numericUpDown14.Value);
            int Vvt = Convert.ToInt16(numericUpDown15.Value);

            clsCommons.lstTarget.Clear();

            for (int i = 0; i < numSomuctieu.Value; i++)
            {
                huongbatdau = i * (360 / Convert.ToInt16(numSomuctieu.Value));

                PointF huongBdo = huong(huongbatdau, clsCommons.sizePictureBox);
                PointF huongGocT = huong(huongbatdau+180, clsCommons.sizePictureBox);

                //quan su dich Z=14
                ToaDo td1 = new ToaDo(1, huongBdo.X, huongBdo.Y, Dkm, 14, Hkm, Vvt, "abc");
                ToaDo td2 = new ToaDo(2, huongGocT.X, huongGocT.Y, Dkm, 14, Hkm, Vvt, "abc");

                qd = new List<ToaDo>();
                qd.Add(td1);
                qd.Add(td2);

                mb = new MucTieu("Quân sự (địch)", i, qd, Color.Red);
                if (clsCommons.lstTarget.Contains(mb))
                {
                    clsCommons.lstTarget.Remove(mb);
                }
                clsCommons.lstTarget.Add(mb);
            }
            clsCommons.bonhao = true;
            clsCommons.showBonhao = true;
        }*/

        private void butPhatXaRaKhongGian10_Click(object sender, EventArgs e)
        {
            butPhatXaRaKhongGian10.BackColor = Color.Blue;
            butPhatXaTuongDuong11.BackColor = Color.White;
        }

        private void butPhatXaTuongDuong11_Click(object sender, EventArgs e)
        {
            butPhatXaRaKhongGian10.BackColor = Color.White;
            butPhatXaTuongDuong11.BackColor = Color.Blue;
        }

        private void btnNhieuMucTieu_Click(object sender, EventArgs e)
        {
            int huongbatdau;

            int Dkm = Convert.ToInt16(numericUpDown13.Value);
            int Hkm = Convert.ToInt16(numericUpDown14.Value);
            int Vvt = Convert.ToInt16(numericUpDown15.Value);

            clsCommons.lstTarget.Clear();

            for (int i = 0; i < numSomuctieu.Value; i++)
            {
                huongbatdau = i * (360 / Convert.ToInt16(numSomuctieu.Value));

                PointF huongBdo = huong(huongbatdau, clsCommons.sizePictureBox);
                PointF huongGocT = huong(huongbatdau + 180, clsCommons.sizePictureBox);

                //quan su dich Z=14
                ToaDo td1 = new ToaDo(1, huongBdo.X, huongBdo.Y, Dkm, 14, Hkm, Vvt, "abc");
                ToaDo td2 = new ToaDo(2, huongGocT.X, huongGocT.Y, Dkm, 14, Hkm, Vvt, "abc");

                qd = new List<ToaDo>();
                qd.Add(td1);
                qd.Add(td2);

                mb = new MucTieu("Quân sự (địch)", i, qd, Color.Red);
                if (clsCommons.lstTarget.Contains(mb))
                {
                    clsCommons.lstTarget.Remove(mb);
                }
                clsCommons.lstTarget.Add(mb);
            }
            clsCommons.bonhao = true;
            clsCommons.showBonhao = true;
        }

        private void button20_Click(object sender, EventArgs e)
        {
            foreach (Control ctrl in panel18.Controls)
            {
                ctrl.Dispose();
            }
            panel18.Controls.Add(new UserControl3vongtron());
        }

        private void button24_Click(object sender, EventArgs e)
        {
            foreach (Control ctrl in panel18.Controls)
            {
                ctrl.Dispose();
            }
            panel18.Controls.Add(new UserControl6vongtron());
        }

        private void button25_Click(object sender, EventArgs e)
        {
            foreach (Control ctrl in panel18.Controls)
            {
                ctrl.Dispose();
            }
            panel18.Controls.Add(new UserControl5vongtron());
        }

        private void button46_Click(object sender, EventArgs e)
        {
            clsCommons.bamsatmuctieu = false;
        }

        private void button47_Click(object sender, EventArgs e)
        {
            clsCommons.bamsatmuctieu = true;
        }

        private void button44_Click_1(object sender, EventArgs e)
        {
            panel16.Visible = false;
            panelDSmuctieu.Visible = true;
            Loaddulieu();
        }

        private void chckTaonhieus_CheckedChanged(object sender, EventArgs e)
        {
            pictureBox1.Visible = true;
            pictureBox1.Parent = this;
            pictureBox1.BackColor = Color.Transparent;
        }

        private void button53_Click_1(object sender, EventArgs e)
        {
            int Dkm = Convert.ToInt16(numericUpDown22.Value);
            int Bdo = Convert.ToInt16(numericUpDown21.Value);
            int Hkm = Convert.ToInt16(numericUpDown23.Value);
            int GocT = Convert.ToInt16(numericUpDown24.Value);
            int Vvt = Convert.ToInt16(numericUpDown30.Value);

            PointF huongBdo = huong(Bdo, clsCommons.sizePictureBox);
            PointF huongGocT = huong(GocT, clsCommons.sizePictureBox);

            //quan su dich Z=14
            ToaDo td1 = new ToaDo(1, huongBdo.X, huongBdo.Y, Dkm, 14, Hkm, Vvt, "abc");
            ToaDo td2 = new ToaDo(2, huongGocT.X, huongGocT.Y, Dkm, 14, Hkm, Vvt, "abc");

            qd = new List<ToaDo>();
            qd.Add(td1);
            qd.Add(td2);
            //MucTieu mb = new MucTieu("Quân sự (địch)", 5, qd, Color.Red);

            button4.Enabled = true;

            mb = new MucTieu("Quân sự (địch)", 3, qd, Color.Red);
            if (clsCommons.lstTarget.Contains(mb))
            {
                clsCommons.lstTarget.Remove(mb);
            }
            clsCommons.lstTarget.Add(mb);

            chonmuctieuBam.Items.Clear();
            foreach (var item in clsCommons.lstTarget)
            {
                chonmuctieuBam.Items.Add(item.ID);
            }
        }

        private void button55_Click(object sender, EventArgs e)
        {
            button4.Enabled = false;

            int Dkm = Convert.ToInt16(numericUpDown26.Value);
            int Bdo = Convert.ToInt16(numericUpDown25.Value);
            int Hkm = Convert.ToInt16(numericUpDown27.Value);
            int GocT = Convert.ToInt16(numericUpDown28.Value);
            int Vvt = Convert.ToInt16(numericUpDown31.Value);

            PointF huongBdo = huong(Bdo, clsCommons.sizePictureBox);
            PointF huongGocT = huong(GocT, clsCommons.sizePictureBox);

            //quan su dich Z=14
            ToaDo td1 = new ToaDo(1, huongBdo.X, huongBdo.Y, Dkm, 14, Hkm, Vvt, "abc");
            ToaDo td2 = new ToaDo(2, huongGocT.X, huongGocT.Y, Dkm, 14, Hkm, Vvt, "abc");

            qd = new List<ToaDo>();
            qd.Add(td1);
            qd.Add(td2);
            //MucTieu mb = new MucTieu("Quân sự (địch)", 5, qd, Color.Red);

            button4.Enabled = true;

            mb = new MucTieu("Quân sự (địch)", 4, qd, Color.Red);
            if (clsCommons.lstTarget.Contains(mb))
            {
                clsCommons.lstTarget.Remove(mb);
            }
            clsCommons.lstTarget.Add(mb);

            chonmuctieuBam.Items.Clear();
            foreach (var item in clsCommons.lstTarget)
            {
                chonmuctieuBam.Items.Add(item.ID);
            }
        }

        private void button57_Click_1(object sender, EventArgs e)
        {
            if (btnTatmoVongTron.BackColor != Color.Blue)
            {
                clsCommons.tatmovongtron = false;
                btnTatmoVongTron.BackColor = Color.Blue;
            }
            else
            {
                clsCommons.tatmovongtron = true;
            }
        }

        private void button57_Click_2(object sender, EventArgs e)
        {
            foreach (Control crtl in panel18.Controls)
            {
                crtl.Dispose();
            }
            Control user = new UserControl3vongtron();
            user.Size = panel18.Size;
            panel18.Controls.Add(user);
        }

        private void button61_Click(object sender, EventArgs e)
        {
            foreach (Control crtl in panel18.Controls)
            {
                crtl.Dispose();
            }
            Control user = new UserControl5vongtron();
            user.Size = panel18.Size;
            panel18.Controls.Add(user);
        }

        private void button62_Click(object sender, EventArgs e)
        {
            foreach (Control crtl in panel18.Controls)
            {
                crtl.Dispose();
            }
            Control user = new UserControl6vongtron();
            user.Size = panel18.Size;
            panel18.Controls.Add(user);
        }

        private void btnmovongtron_Click(object sender, EventArgs e)
        {
            RadaA1.TatMoVongTron = true;
        }

        private void btntatvongtrong_Click(object sender, EventArgs e)
        {
            RadaA1.TatMoVongTron = false;
        }
    }
}
